﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using MigSharp;
using SnippetBox.Core.Data.Context;

namespace SnippetBox.Core.Data.Migrations {
    [MigrationExport]
    public class Migration1 : IMigration {

        public void Up(IDatabase db) {
            // Remove old favorite tables and keys
            db.Tables["UserFavoriteSnippets"].Drop();

            db.CreateTable("Favorites", "FavoriteId")
                .WithNotNullableColumn("DateCreated", DbType.DateTime).HavingCurrentDateTimeAsDefault()
                .WithPrimaryKeyColumn("FavoriteId", DbType.Int32).AsIdentity()
                .WithNullableColumn("Snippet_SnippetId", DbType.Int32)
                .WithNullableColumn("User_UserId", DbType.Int32);
            
            db.Tables["Favorites"].AddForeignKeyTo("Snippets", "Favorite_Snippet")
                .Through("Snippet_SnippetId", "SnippetId");
            
            db.Tables["Favorites"].AddForeignKeyTo("Users", "Favorite_User")
                .Through("User_UserId", "UserId");

        }
    
    }
}
